<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>

<body>
  <div id="app">
    {{msg}}
    <br>
    {{reverseMsg}}-{{reverseMsg}}
    <br>
    {{getMsg()}}-{{getMsg()}}
  </div>
  <script>

    var vm = new Vue({
      el: "#app",
      data: {
        msg: "helloworld",
        user:{
          name:"xiaoming",
          age:20
        }
      },
      //数据会缓存
      computed: {
        reverseMsg() {
          console.log(1)
          return this.msg.split('').reverse().join('')
        }
      },
      //定义方法,数据不会被缓存
      methods: {
        getMsg() {
          console.log(2)
          return this.msg.split('').reverse().join('')
        }
      },
      watch: {
        msg(newval, oldval) {
          console.log(newval, oldval)
        },

        // user(newval, oldval){
        //   console.log(newval, oldval)
        // }

        user:{
          handler(newval, oldval){
            console.log(newval, oldval)
          },
          deep:true
        }
      }


    })
  </script>
</body>

</html>